package com.panda.web.service.product.impl;

import com.panda.common.utils.SecurityUtils;
import com.panda.web.domain.dto.ProductDTO;
import com.panda.web.domain.vo.product.ProOpenidVO;
import com.panda.web.domain.vo.product.ProductAdvantage;
import com.panda.web.domain.vo.product.ProductOpenidVO;
import com.panda.web.domain.vo.product.ProductVO;
import com.panda.web.entity.order.WechatOrder;
import com.panda.web.entity.product.OpenidProduct;
import com.panda.web.entity.product.Product;
import com.panda.web.entity.wechat.WechatUser;
import com.panda.web.mapper.order.WechatOrderMapper;
import com.panda.web.mapper.product.OpenidProductMapper;
import com.panda.web.mapper.product.ProductMapper;
import com.panda.web.mapper.wechat.WechatUserMapper;
import com.panda.web.service.product.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.BeanUtils;

import java.text.SimpleDateFormat;
import java.time.Duration;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.*;

import lombok.extern.slf4j.Slf4j;
import com.panda.web.utils.pageutils.PageResult;
import org.springframework.transaction.annotation.Transactional;


/**
 * 产品
 * Service业务层处理
 *
 * @author cpanda
 * @date 2025-03-03
 */
@Slf4j
@Service
public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> implements IProductService {
    @Autowired
    ProductMapper productMapper;
    @Autowired
    OpenidProductMapper openidProductMapper;
    @Autowired
    WechatUserMapper userMapper;
    @Autowired
    WechatOrderMapper orderMapper;

    /**
     * 分页查询
     *
     * @param dto
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public PageResult<ProductVO> PageList(ProductDTO dto, Integer pageNum, Integer pageSize) {

        Page<Product> page = new Page<>(pageNum, pageSize);
        QueryWrapper<Product> queryWrapper = new QueryWrapper();//需要处理查询条件
        queryWrapper.eq("deleted", 0);//未删除的
        queryWrapper.orderByAsc("sort");
        if (Objects.equals(dto.getReturnNot(), 1)) {//如果他是1 不返回=1的
            queryWrapper.ne("return_ne", 1);
        }
//        queryWrapper.ne("product_id",10);
        IPage<Product> productIPage = productMapper.selectPage(page, queryWrapper);
        long total = productIPage.getTotal();
        List<Product> records = productIPage.getRecords();
        List<ProductVO> voList = productVoToList(records);//封装vo数据方法

        return new PageResult<>(voList, total, pageNum, pageSize);
    }

    /**
     * 无分页查询
     *
     * @param dto
     * @return
     */
    @Override
    public List<ProductVO> choiceList(ProductDTO dto) {
        QueryWrapper<Product> queryWrapper = new QueryWrapper();//需要处理查询条件
        queryWrapper.orderByAsc("sort");
        queryWrapper.eq("deleted", 0);//未删除的
        if (Objects.equals(dto.getReturnNot(), 1)) {//如果他是1 不返回=1的
            queryWrapper.ne("return_not", 1);
        }
//        queryWrapper.ne("product_id",10);
        //构建查询条件
        List<Product> productList = productMapper.selectList(queryWrapper);
        List<ProductVO> voList = productVoToList(productList);//封装vo数据方法
        return voList;
    }

    //无token
    @Override
    public List<ProductVO> ListAll(ProductDTO dto) {
        QueryWrapper<Product> queryWrapper = new QueryWrapper();//需要处理查询条件
        queryWrapper.orderByAsc("sort");
        queryWrapper.eq("deleted", 0);//未删除的
        if (Objects.equals(dto.getReturnNot(), 1)) {//如果他是1 不返回=1的
            queryWrapper.ne("return_not", 1);
        }
        //构建查询条件
        List<Product> productList = productMapper.selectList(queryWrapper);
        List<ProductVO> voList = productVoToListAAA(productList);//封装vo数据方法
        return voList;
    }

    /**
     * 获取套餐等级
     *
     * @param openid
     */
    @Override
    public Long getDayOpenidProduct(String openid) {
        List<OpenidProduct> openidProductList = openidProductMapper.findByOpenidAndOTFEN(openid);
        if (openidProductList != null && !openidProductList.isEmpty()) {
            OpenidProduct openidProduct = openidProductList.get(0);
            String day = openidProduct.getDay();//套餐天数
            String creationTime = openidProduct.getCreationTime();//创建时间
            //计算剩余时间  当前时间
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
            LocalDateTime createTime = LocalDateTime.parse(creationTime, formatter);

            int totalDays = Integer.parseInt(day);
            LocalDateTime expireTime = createTime.plusDays(totalDays);
            LocalDateTime now = LocalDateTime.now();

            long remainingDays = Duration.between(now, expireTime).toDays();

            if (remainingDays < 0) {
                return -1l;
            } else if (remainingDays == 0) {
               return 0l;
            } else {
                return remainingDays;
            }

        } else {
            return 0l;
        }


    }
//

    /**
     * 回显数据
     *
     * @param productId
     * @return
     */
    @Override
    public ProductVO selectById(Long productId) {
        ProductVO vo = new ProductVO();
        Product product = productMapper.selectById(productId);
        BeanUtils.copyProperties(product, vo);
        return vo;
    }

    /**
     * 新增
     *
     * @param dto
     * @return
     */
    @Override
    public int insert(ProductDTO dto) {
        Long userId = SecurityUtils.getUserId();
        Product product = new Product();
        BeanUtils.copyProperties(dto, product);
        product.setCreateTime(new Date());
        product.setUpdateTime(new Date());
        product.setCreateById(userId);
        productMapper.insert(product);
        return 1;
    }

    /**
     * 修改数据
     *
     * @param dto
     * @return
     */
    @Override
    public int updateProductById(ProductDTO dto) {
        Long productId = dto.getProductId();
        Product product = productMapper.selectById(productId);
        product.setProductPrice(dto.getProductPrice());
        product.setUpdateTime(new Date());
        productMapper.updateById(product);
        return 1;
    }

    /**
     * 删除数据(逻辑删除)
     *
     * @param ids
     * @return
     */
    @Override
    public int removeByProductIds(List<Long> ids) {
        for (Long id : ids) {
            Product product = productMapper.selectById(id);
            product.setDeleted(1);
            productMapper.updateById(product);
        }
        return 1;
    }

    /**
     * 该客户所购买的产品
     *
     * @param openid
     * @return
     */
    @Override
    public ProductOpenidVO getOpenidByProduct(String openid) {
        ProductOpenidVO vo = new ProductOpenidVO();
        String status = "0";
        List<Long> productIds = openidProductMapper.findByOpenid(openid, status);
        // 如果列表不为空，获取最大值；否则返回 0
        Long maxProductId = productIds.isEmpty() ? 0l : Collections.max(productIds);
        WechatUser wechatUser = userMapper.findByOpenId(openid);
        vo.setPdfFrequency(wechatUser.getPdfFrequency());
        vo.setMax(maxProductId);
        vo.setProductIdList(productIds);
        return vo;
    }

    @Override
    public ProductOpenidVO getOpenidAiByProduct(String openid) {
        ProductOpenidVO vo = new ProductOpenidVO();
        String status = "0";
        List<Long> productIds = openidProductMapper.findByOpenidByAi(openid, status);
        // 如果列表不为空，获取最大值；否则返回 0
        Long maxProductId = productIds.isEmpty() ? 0l : Collections.max(productIds);
        WechatUser wechatUser = userMapper.findByOpenId(openid);
        vo.setPdfFrequency(wechatUser.getPdfFrequency());
        vo.setMax(maxProductId);
        vo.setProductIdList(productIds);
        return vo;
    }

    /**
     * 试用套餐
     *
     * @param openid
     * @return
     */
    @Override
    public int trialStatus(String openid) {
        throw new RuntimeException("请购买套餐");
//        WechatUser wechatUser = userMapper.findByOpenId(openid);
//        wechatUser.setTrialStatus("1"); // 开始试用
//
//        Date date = new Date();
//        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        String stringTime = simpleDateFormat.format(date);
//        wechatUser.setTrialStartTime(stringTime); // 设置试用开始时间
//
//// 计算试用结束时间为当前时间加24小时
//        Calendar calendar = Calendar.getInstance();
//        calendar.setTime(date);
//        calendar.add(Calendar.HOUR_OF_DAY, 24); // 将当前时间加24小时（一天）
//
//// 获取结束时间
//        Date endDate = calendar.getTime();
//
//// 将结束时间格式化为字符串
//        String endString = simpleDateFormat.format(endDate);
//        wechatUser.setTrialEndTime(endString);
//
//        userMapper.updateById(wechatUser);
//        return 1;

    }

    /**
     * 手动添加套餐
     */

    @Transactional
    @Override
    public synchronized int sdProduct(OpenidProduct nOpenidProduct) {
        Date date = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String formattedDate = simpleDateFormat.format(date);

        Product product = productMapper.selectById(nOpenidProduct.getProductId());//产品表
        OpenidProduct openidProduct = openidProductMapper.findByProductIdAndOpenId(nOpenidProduct.getOpenid(), nOpenidProduct.getProductId());

        //判断是否为空，为空 说明第一次购买这个产品，否则不是第一次
        if (openidProduct != null) {//更新原商品状态为可使用
            if (Objects.equals(openidProduct.getStatus(), "0")) {//说明没到期
                //在该套餐的上加时间
                if (openidProduct.getProductId() == 2 || openidProduct.getProductId() == 3 || openidProduct.getProductId() == 4) {
                    openidProduct.setDay(String.valueOf(Integer.valueOf(openidProduct.getDay()) + Integer.valueOf(openidProduct.getProductType())));
                }
                if (product.getProductId() == 2 || product.getProductId() == 3) {
                    openidProduct.setAiCount(openidProduct.getAiCount() + product.getAiCount());
                }
                openidProduct.setCount(openidProduct.getCount() + 1);
                openidProductMapper.updateById(openidProduct);
            } else {//到期了
                openidProduct.setStatus("0");
                openidProduct.setCreationTime(formattedDate);//新购买时间，更新购买次数
                if (product.getProductId() == 2 || product.getProductId() == 3) {
                    openidProduct.setAiCount(openidProduct.getAiCount() + product.getAiCount());
                }
                openidProduct.setCreateTime(date);
                openidProduct.setCount(openidProduct.getCount() + 1);
                openidProductMapper.updateById(openidProduct);
            }

        } else {
            nOpenidProduct.setOpenid(nOpenidProduct.getOpenid());
            nOpenidProduct.setProductId(nOpenidProduct.getProductId());
            nOpenidProduct.setProductType(product.getProductType());
            nOpenidProduct.setProductName(product.getProductName());
            nOpenidProduct.setProductPrice(product.getProductPrice());
            nOpenidProduct.setAiCount(product.getAiCount());
            nOpenidProduct.setDay(product.getProductType());
            nOpenidProduct.setCreateTime(date);
            nOpenidProduct.setCreationTime(formattedDate);
            nOpenidProduct.setCount(1);
            openidProductMapper.insert(nOpenidProduct);
        }
        WechatUser wechatUser = userMapper.findByOpenId(nOpenidProduct.getOpenid());
        WechatOrder wechatOrder = new WechatOrder();
        wechatOrder.setOpenid(nOpenidProduct.getOpenid());
        wechatOrder.setNickName(wechatUser.getNickname());
        wechatOrder.setTotalFee(product.getProductPrice());
        wechatOrder.setCreateTime(date);
        wechatOrder.setPayStatus("已支付");
        wechatOrder.setRefundStatus("未退款");
        wechatOrder.setPayTime(date);
        wechatOrder.setProductId(product.getProductId());
        wechatOrder.setProductName(product.getProductName());
        wechatOrder.setOrderType("1");
        orderMapper.insert(wechatOrder);
        //生成订单
        return 1;
    }

    /**
     * 获取该用户购买的所有套餐
     *
     * @param dto
     * @return
     */
    @Override
    public List<OpenidProduct> getUserProduct(OpenidProduct dto) {
        List<OpenidProduct> products = openidProductMapper.findByOpenidList(dto.getOpenid(), "0");
        return products;
    }

    /**
     * 关闭用户套餐
     *
     * @param dto
     * @return
     */
    @Override
    public int gbUserProduct(OpenidProduct dto) {
        Long id = dto.getId();
        OpenidProduct openidProduct = openidProductMapper.selectById(id);
        openidProduct.setStatus("1");
        openidProductMapper.updateById(openidProduct);
        return 1;
    }


//    /**
//     * 用户已购买的产品列表
//     * @param dto
//     * @param pageNum
//     * @param pageSize
//     * @return
//     */
//    @Override
//    public PageResult<ProOpenidVO> proOpenidList(ProductDTO dto, Integer pageNum, Integer pageSize) {
//        Page<OpenidProduct> page = new Page<>(pageNum, pageSize);
//        QueryWrapper<OpenidProduct> queryWrapper = new QueryWrapper();//需要处理查询条件
//        queryWrapper.eq("status", 1);//未删除的
//        IPage<OpenidProduct> productIPage = openidProductMapper.selectPage(page, queryWrapper);
//        long total = productIPage.getTotal();
//        List<OpenidProduct> records = productIPage.getRecords();
//        List<ProOpenidVO> voList = OpenidProductToList(records);//封装vo数据方法
//
//        return new PageResult<>(voList, total, pageNum, pageSize);
//    }
//    //处理用户购买产品的VO数据
//    private List<ProOpenidVO> OpenidProductToList(List<OpenidProduct> records) {

    //    }
    private List<ProductVO> productVoToListAAA(List<Product> productList) {
        List<ProductVO> voList = new ArrayList<>();
        if (productList.size() > 0 && !productList.isEmpty()) {
            for (Product product : productList) {
                ProductVO vo = new ProductVO();
                BeanUtils.copyProperties(product, vo);
                Long productId = product.getProductId();

                if (productId == 1) {
                    List<ProductAdvantage> advantageList = new ArrayList<>();
                    List<String> aaa1 = new ArrayList<>(Arrays.asList("大数据精准预判通过概率", "专属竞争力优势分析", "就业提升方案", "简历话术急救包", "网申避雷指南"));
                    for (String aa : aaa1) {
                        ProductAdvantage productAdvantage = new ProductAdvantage();
                        productAdvantage.setName(null);
                        productAdvantage.setValue(aa);
                        advantageList.add(productAdvantage);
                    }
                    vo.setAdvantageList(advantageList);
                    List<String> aa2 = new ArrayList<>();
                    vo.setTermsGamblingList(aa2);
                }
                if (productId == 2) {
                    List<ProductAdvantage> advantageList = new ArrayList<>();
                    List<String> aaa1 = new ArrayList<>(Arrays.asList("每日岗位一对一精准推送", "个性化选岗建议，优化求职策略", "智能简历定制，直达HR内心"));
                    for (String aa : aaa1) {
                        ProductAdvantage productAdvantage = new ProductAdvantage();
                        productAdvantage.setName(null);
                        productAdvantage.setValue(aa);
                        advantageList.add(productAdvantage);
                    }
                    vo.setAdvantageList(advantageList);
                    List<String> aa2 = new ArrayList<>();
                    vo.setTermsGamblingList(aa2);
                }
                if (productId == 3) {
                    List<ProductAdvantage> advantageList = new ArrayList<>();
                    List<String> aaa1 = new ArrayList<>(Arrays.asList("网申透视仪:", "理论储备仓:", "笔试动态盾:", "面试真沙盘:"));
                    List<String> aaa2 = new ArrayList<>(Arrays.asList("AI精准匹配岗位，简历定制无忧", "120h+笔面试基础理论课程", "AI智能题库，精准刷题", "职规师2次1v1深度人工模拟面试"));

                    for (int i = 0; i < 4; i++) {
                        ProductAdvantage productAdvantage = new ProductAdvantage();
                        productAdvantage.setName(aaa2.get(i));
                        productAdvantage.setValue(aaa1.get(i));
                        advantageList.add(productAdvantage);
                    }

                    vo.setAdvantageList(advantageList);
                    List<String> aa2 = new ArrayList<>(Arrays.asList("网申不过退50%", "笔试不过退20%"));
                    vo.setTermsGamblingList(aa2);
                }
                if (productId == 4) {
                    List<ProductAdvantage> advantageList = new ArrayList<>();
                    List<String> aaa1 = new ArrayList<>(Arrays.asList("人岗匹配", "精准网申", "笔试突击", "全真面试"));
                    List<String> aaa2 = new ArrayList<>(Arrays.asList("-每年4000个岗位推荐,就业顾问辅助精准推岗", "-重点岗位不限次辅导与简历修改", "—全面的基础课程+针对性笔试真题", "一不限次面试辅导 一不限次数深度模拟(结构化+半结构化+无领导)"));

                    for (int i = 0; i < 4; i++) {
                        ProductAdvantage productAdvantage = new ProductAdvantage();
                        productAdvantage.setName(aaa2.get(i));
                        productAdvantage.setValue(aaa1.get(i));
                        advantageList.add(productAdvantage);
                    }

                    vo.setAdvantageList(advantageList);
                    List<String> aa2 = new ArrayList<>(Arrays.asList("网申不过退80%", "笔试不过退50%"));
                    vo.setTermsGamblingList(aa2);
                }
                if (productId == 8) {
                    List<ProductAdvantage> advantageList = new ArrayList<>();
                    List<String> aaa1 = new ArrayList<>(Arrays.asList("人岗匹配", "精准网申", "笔试突击", "全真面试"));
                    List<String> aaa2 = new ArrayList<>(Arrays.asList("——每年3000个岗位推荐", "——重点岗位不限次辅导与简历修改", "——全面的基础课程+针对性笔试真题", "——不限次面试辅导 ——五轮深度模拟（结构化+半结构化+无领导）"));
                    for (int i = 0; i < 4; i++) {
                        ProductAdvantage productAdvantage = new ProductAdvantage();
                        productAdvantage.setName(aaa2.get(i));
                        productAdvantage.setValue(aaa1.get(i));
                        advantageList.add(productAdvantage);
                    }
                    vo.setAdvantageList(advantageList);
                    List<String> aa2 = new ArrayList<>(Arrays.asList("网申不过退80%", "笔试不过退50%"));
                    vo.setTermsGamblingList(aa2);
                }
                if (productId == 9) {
                    List<ProductAdvantage> advantageList = new ArrayList<>();
                    List<String> aaa1 = new ArrayList<>(Arrays.asList("一年规划及跟踪，实习岗位每日推荐", "金牌导师一对一面试指导，直击面试官内心需求", "针对企业进行专项指导（网申、简历、笔面试）", "五轮深度模拟，逐条反馈，提升能力", "涵盖秋招春招两轮招聘"));
                    for (String aa : aaa1) {
                        ProductAdvantage productAdvantage = new ProductAdvantage();
                        productAdvantage.setName(null);
                        productAdvantage.setValue(aa);
                        advantageList.add(productAdvantage);
                    }
                    vo.setAdvantageList(advantageList);
                    List<String> aa2 = new ArrayList<>(Arrays.asList("网申不过退80%", "笔试不过退50%"));
                    vo.setTermsGamblingList(aa2);
                }
                if (productId == 5) {
                    List<ProductAdvantage> advantageList = new ArrayList<>();
                    List<String> aaa1 = new ArrayList<>(Arrays.asList("专业职业性格测试", "职规师专业指导扫清发展障碍", "提供最现实的职业生涯规划建议"));
                    for (String aa : aaa1) {
                        ProductAdvantage productAdvantage = new ProductAdvantage();
                        productAdvantage.setName(null);
                        productAdvantage.setValue(aa);
                        advantageList.add(productAdvantage);
                    }
                    vo.setAdvantageList(advantageList);
//                    List<String> aa2 = new ArrayList<>(Arrays.asList("网申不过退80%", "笔试不过退50%"));
                    vo.setTermsGamblingList(new ArrayList<>());
                }
                if (productId == 7) {
                    List<ProductAdvantage> advantageList = new ArrayList<>();
                    List<String> aaa1 = new ArrayList<>(Arrays.asList("行业导师模拟，还原真实考场状态，感受群面压力", "通过精细点评，提高面试能力，达到目标企业的面试需求", "针对性训练，结合行业技能，了解目标企业人才画像，精准表达，提升面试硬实力。"));
                    for (String aa : aaa1) {
                        ProductAdvantage productAdvantage = new ProductAdvantage();
                        productAdvantage.setName(null);
                        productAdvantage.setValue(aa);
                        advantageList.add(productAdvantage);
                    }
                    vo.setAdvantageList(advantageList);
                    //List<String> aa2 = new ArrayList<>(Arrays.asList("网申不过退80%", "笔试不过退50%"));
                    vo.setTermsGamblingList(new ArrayList<>());
                }
                if (productId == 10) {
                    List<ProductAdvantage> advantageList = new ArrayList<>();
                    List<String> aaa1 = new ArrayList<>(Arrays.asList("AI深度学习了央国企所有面试题库", "可根据报考岗位和条件深度模拟", "AI数字人扮演HR角色", "深度练一次可抵十次"));
                    for (String aa : aaa1) {
                        ProductAdvantage productAdvantage = new ProductAdvantage();
                        productAdvantage.setName(null);
                        productAdvantage.setValue(aa);
                        advantageList.add(productAdvantage);
                    }
                    vo.setAdvantageList(advantageList);
                    //List<String> aa2 = new ArrayList<>(Arrays.asList("网申不过退80%", "笔试不过退50%"));
                    vo.setTermsGamblingList(new ArrayList<>());
                }
                if (productId == 11) {
                    List<ProductAdvantage> advantageList = new ArrayList<>();
                    vo.setAdvantageList(advantageList);
                    //List<String> aa2 = new ArrayList<>(Arrays.asList("网申不过退80%", "笔试不过退50%"));
                    vo.setTermsGamblingList(new ArrayList<>());
                }
                voList.add(vo);
            }
        }
        return voList;
    }


    // 处理VO数据封装
    private List<ProductVO> productVoToList(List<Product> productList) {
        List<ProductVO> voList = new ArrayList<>();
        if (productList.size() > 0 && !productList.isEmpty()) {
            for (Product product : productList) {
                ProductVO vo = new ProductVO();
                BeanUtils.copyProperties(product, vo);
                Long productId = product.getProductId();

                String openid = SecurityUtils.getLoginUser().getOpenid();
//                String openid = "o9Zsy51Cedmv9DBC98e8q21ssVaw";
                if (!Objects.equals(openid, null)) {
                    if (productId == 1) {
                        OpenidProduct dayA = openidProductMapper.findByProductIdAndOpenIdAndStatus(openid, productId);
                        if (dayA == null) {
                            vo.setDay("0");
                        } else {
                            vo.setDay("永久");
                        }
                    }
                    if (productId == 2 || productId == 3 || productId == 4 || productId == 8 || productId == 9) {
                        OpenidProduct dayB = openidProductMapper.findByProductIdAndOpenIdAndStatus(openid, productId);
                        if (dayB == null) {
                            vo.setDay("0");
                        } else {
                            String day = dayB.getDay();//产品天数
                            String creationTime = dayB.getCreationTime();//购买时间
                            long days = calculateRemainingDays(day, creationTime);
                            vo.setDay(String.valueOf(days));
                        }

                    }


                }


                if (productId == 1) {
                    List<ProductAdvantage> advantageList = new ArrayList<>();
                    List<String> aaa1 = new ArrayList<>(Arrays.asList("大数据精准预判通过概率", "专属竞争力优势分析", "就业提升方案", "简历话术急救包", "网申避雷指南"));
                    for (String aa : aaa1) {
                        ProductAdvantage productAdvantage = new ProductAdvantage();
                        productAdvantage.setName(null);
                        productAdvantage.setValue(aa);
                        advantageList.add(productAdvantage);
                    }
                    vo.setAdvantageList(advantageList);
                    List<String> aa2 = new ArrayList<>();
                    vo.setTermsGamblingList(aa2);
                }
                if (productId == 2) {
                    List<ProductAdvantage> advantageList = new ArrayList<>();
                    List<String> aaa1 = new ArrayList<>(Arrays.asList("每日岗位一对一精准推送", "个性化选岗建议，优化求职策略", "智能简历定制，直达HR内心"));
                    for (String aa : aaa1) {
                        ProductAdvantage productAdvantage = new ProductAdvantage();
                        productAdvantage.setName(null);
                        productAdvantage.setValue(aa);
                        advantageList.add(productAdvantage);
                    }
                    vo.setAdvantageList(advantageList);
                    List<String> aa2 = new ArrayList<>();
                    vo.setTermsGamblingList(aa2);
                }
                if (productId == 3) {
                    List<ProductAdvantage> advantageList = new ArrayList<>();
                    List<String> aaa1 = new ArrayList<>(Arrays.asList("网申透视仪:", "理论储备仓:", "笔试动态盾:", "面试真沙盘:"));
                    List<String> aaa2 = new ArrayList<>(Arrays.asList("AI精准匹配岗位，简历定制无忧", "120h+笔面试基础理论课程", "AI智能题库，精准刷题", "职规师2次1v1深度人工模拟面试"));

                    for (int i = 0; i < 4; i++) {
                        ProductAdvantage productAdvantage = new ProductAdvantage();
                        productAdvantage.setName(aaa2.get(i));
                        productAdvantage.setValue(aaa1.get(i));
                        advantageList.add(productAdvantage);
                    }

                    vo.setAdvantageList(advantageList);
                    List<String> aa2 = new ArrayList<>(Arrays.asList("网申不过退50%", "笔试不过退20%"));
                    vo.setTermsGamblingList(aa2);
                }
                if (productId == 4) {
                    List<ProductAdvantage> advantageList = new ArrayList<>();
                    List<String> aaa1 = new ArrayList<>(Arrays.asList("人岗匹配", "精准网申", "笔试突击", "全真面试"));
                    List<String> aaa2 = new ArrayList<>(Arrays.asList("-每年4000个岗位推荐,就业顾问辅助精准推岗", "-重点岗位不限次辅导与简历修改", "—全面的基础课程+针对性笔试真题", "一不限次面试辅导 一不限次数深度模拟(结构化+半结构化+无领导)"));

                    for (int i = 0; i < 4; i++) {
                        ProductAdvantage productAdvantage = new ProductAdvantage();
                        productAdvantage.setName(aaa2.get(i));
                        productAdvantage.setValue(aaa1.get(i));
                        advantageList.add(productAdvantage);
                    }

                    vo.setAdvantageList(advantageList);
                    List<String> aa2 = new ArrayList<>(Arrays.asList("网申不过退80%", "笔试不过退50%"));
                    vo.setTermsGamblingList(aa2);
                }
                if (productId == 8) {
                    List<ProductAdvantage> advantageList = new ArrayList<>();
                    List<String> aaa1 = new ArrayList<>(Arrays.asList("金牌导师一对一面试指导，真击面试官内心需求", "针对企业进行专项指导(网申、简历、笔面试)", "五轮深度模拟，逐条反馈，提升能力", "涵盖秋招春招两轮招聘"));
                    for (String aa : aaa1) {
                        ProductAdvantage productAdvantage = new ProductAdvantage();
                        productAdvantage.setName(null);
                        productAdvantage.setValue(aa);
                        advantageList.add(productAdvantage);
                    }
                    vo.setAdvantageList(advantageList);
                    List<String> aa2 = new ArrayList<>(Arrays.asList("网申不过退80%", "笔试不过退50%"));
                    vo.setTermsGamblingList(aa2);
                }
                if (productId == 9) {
                    List<ProductAdvantage> advantageList = new ArrayList<>();
                    List<String> aaa1 = new ArrayList<>(Arrays.asList("一年规划及跟踪，实习岗位每日推荐", "金牌导师一对一面试指导，直击面试官内心需求", "针对企业进行专项指导（网申、简历、笔面试）", "五轮深度模拟，逐条反馈，提升能力", "涵盖秋招春招两轮招聘"));
                    for (String aa : aaa1) {
                        ProductAdvantage productAdvantage = new ProductAdvantage();
                        productAdvantage.setName(null);
                        productAdvantage.setValue(aa);
                        advantageList.add(productAdvantage);
                    }
                    vo.setAdvantageList(advantageList);
                    List<String> aa2 = new ArrayList<>(Arrays.asList("网申不过退80%", "笔试不过退50%"));
                    vo.setTermsGamblingList(aa2);
                }
                if (productId == 5) {
                    List<ProductAdvantage> advantageList = new ArrayList<>();
                    List<String> aaa1 = new ArrayList<>(Arrays.asList("专业职业性格测试", "职规师专业指导扫清发展障碍", "提供最现实的职业生涯规划建议"));
                    for (String aa : aaa1) {
                        ProductAdvantage productAdvantage = new ProductAdvantage();
                        productAdvantage.setName(null);
                        productAdvantage.setValue(aa);
                        advantageList.add(productAdvantage);
                    }
                    vo.setAdvantageList(advantageList);
//                    List<String> aa2 = new ArrayList<>(Arrays.asList("网申不过退80%", "笔试不过退50%"));
                    vo.setTermsGamblingList(new ArrayList<>());
                }
                if (productId == 7) {
                    List<ProductAdvantage> advantageList = new ArrayList<>();
                    List<String> aaa1 = new ArrayList<>(Arrays.asList("行业导师模拟，还原真实考场状态，感受群面压力", "通过精细点评，提高面试能力，达到目标企业的面试需求", "针对性训练，结合行业技能，了解目标企业人才画像，精准表达，提升面试硬实力。"));
                    for (String aa : aaa1) {
                        ProductAdvantage productAdvantage = new ProductAdvantage();
                        productAdvantage.setName(null);
                        productAdvantage.setValue(aa);
                        advantageList.add(productAdvantage);
                    }
                    vo.setAdvantageList(advantageList);
                    //List<String> aa2 = new ArrayList<>(Arrays.asList("网申不过退80%", "笔试不过退50%"));
                    vo.setTermsGamblingList(new ArrayList<>());
                }
                if (productId == 10) {
                    List<ProductAdvantage> advantageList = new ArrayList<>();
                    List<String> aaa1 = new ArrayList<>(Arrays.asList("AI深度学习了央国企所有面试题库", "可根据报考岗位和条件深度模拟", "AI数字人扮演HR角色", "深度练一次可抵十次"));
                    for (String aa : aaa1) {
                        ProductAdvantage productAdvantage = new ProductAdvantage();
                        productAdvantage.setName(null);
                        productAdvantage.setValue(aa);
                        advantageList.add(productAdvantage);
                    }
                    vo.setAdvantageList(advantageList);
                    //List<String> aa2 = new ArrayList<>(Arrays.asList("网申不过退80%", "笔试不过退50%"));
                    vo.setTermsGamblingList(new ArrayList<>());
                }
                if (productId == 11) {
                    List<ProductAdvantage> advantageList = new ArrayList<>();
                    vo.setAdvantageList(advantageList);
                    //List<String> aa2 = new ArrayList<>(Arrays.asList("网申不过退80%", "笔试不过退50%"));
                    vo.setTermsGamblingList(new ArrayList<>());
                }
                voList.add(vo);
            }
        }
        return voList;
    }

    /**
     * 计算剩余天数
     *
     * @param day          产品天数（字符串格式，如 "90"）
     * @param creationTime 购买时间（字符串格式，如 "yyyy-MM-dd HH:mm:ss"）
     * @return 剩余天数（如果已过期，返回 0）
     */
    public static long calculateRemainingDays(String day, String creationTime) {
        try {
            // 解析购买时间
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
            LocalDateTime purchaseTime = LocalDateTime.parse(creationTime, formatter);

            // 计算到期时间
            int productDays = Integer.parseInt(day); // 将天数转换为整数
            LocalDateTime expiryTime = purchaseTime.plusDays(productDays);

            // 获取当前时间
            LocalDateTime now = LocalDateTime.now();

            // 计算剩余天数
            if (now.isBefore(expiryTime)) {
                return ChronoUnit.DAYS.between(now, expiryTime);
            } else {
                return 0; // 如果已过期，返回 0
            }
        } catch (Exception e) {
            System.err.println("发生错误: " + e.getMessage());
            return -1; // 如果发生错误，返回 -1 表示计算失败
        }
    }

}